package com.springcloud.tools.service.impl;

import com.springcloud.tools.entity.User;
import com.springcloud.tools.repository.UserRepository;
import com.springcloud.tools.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author fuc
 * @create 2020-06-12
 */
@Service
public class UserServiceImpl implements UserService {

  @Resource private UserRepository userRepository;

  @Override
  public void save(User user) {
    userRepository.save(user);
  }

  @Override
  public User getById(String id) {
    return userRepository.findById(id).get();
  }

  @Override
  public User getByName(String name) {
    return userRepository.findByName(name);
  }

  @Override
  public void delete(String id) {
    userRepository.deleteById(id);
  }

  @Override
  public void update(User user) {
    userRepository.delete(user);
    userRepository.save(user);
  }
}
